#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

void swap(char* s1, char* s2, size_t width)
{
	for (size_t i = 0;i < width;i++)
	{
		char temp = *s1;
		*s1 = *s2;
		*s2 = temp;
		s1++;
		s2++;
	}
}
int cmp_int(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}
void print(int *arr, int sz)
{
	for (int i = 0;i < sz;i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
}
void bubble_sort(void* base, size_t sz, size_t width, int(*cmp)(const void* p1, const void*p2 ))
{
	for (size_t i = 0;i < sz - 1;i++)
	{
		for (size_t j = 0;j < sz - 1 - i;j++)
		{
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width )> 0)
			{
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
void test3()
{
	int arr[] = { 3,1,7,8,5,2,4,9,0,6 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_int);
	print(arr, sz);
}
int main()
{
	test3();
	return 0;
}